/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package upc.edu.alquiler.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import upc.edu.alquiler.excepcion.DAOExcepcion;
import upc.edu.alquiler.model.Persona;
import upc.edu.alquiler.util.ConexionBD;


/*
 *
 * @author SONY
 */
public class PersonaDao extends BaseDao {
    
    public Persona consultar(String email) throws DAOExcepcion{
        
		System.out.println("PersonaDAO: obtener(String Persona)");
		Persona pe = new Persona();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
			try {
        		con = ConexionBD.obtenerConexion();
			String query = "select nombres, paterno,contrasena from Persona where email = ?";
			stmt = con.prepareStatement(query);
			stmt = con.prepareStatement(query);
			
                        stmt.setString(1, email);
			rs = stmt.executeQuery();
			
                        if (rs.next()) {
				
				pe.setNombres(rs.getString(1));
				pe.setPaterno(rs.getString(2));
				pe.setContrasena(rs.getString(3));
			}

			} catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new DAOExcepcion(e.getMessage());
			} finally {
				this.cerrarStatement(stmt);
				this.cerrarConexion(con);
			}
            return pe;
    }
}
